package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.TaoBaoMapper;
import com.itheima.pojo.Product;
import com.itheima.service.TaoBaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaoBaoServiceImpl implements TaoBaoService {
    @Autowired
    private TaoBaoMapper taoBaoMapper;
    @Override
    public void add(Product product) {
        taoBaoMapper.add(product);
    }

    @Override
    public Product getById(Long skuId) {
       return taoBaoMapper.getById(skuId);
    }

    @Override
    public PageInfo<Product> pageInfo(Integer pageNum, Integer pageSize, String skuName, String priceUp, String priceDown, String classId, String brandName) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> list=taoBaoMapper.list(skuName, priceUp,priceDown,classId,brandName);

        Page<Product> page = (Page<Product>) list;
        PageInfo<Product> pageInfo = new PageInfo<>();

        pageInfo.setTotal(page.getTotal());
        pageInfo.setList(page.getResult());
        return pageInfo;
    }

    @Override
    public void deleteById(Long skuId) {
        taoBaoMapper.deleteById(skuId);
    }

    @Override
    public void update(Product product) {
        taoBaoMapper.update(product);
    }


}
